package com.sbox.album;

import com.sbox.album.model.AlbumContext;
import com.sbox.util.Utils;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class CreateAlbumActivity extends Activity {
	
	private EditText mEditName = null;
	private Button mBtnOK = null;
	private Button mBtnCancel = null;
	
	private View.OnClickListener mBtnOKListener = new View.OnClickListener() {		
		@Override
		public void onClick(View v) {
			String name = mEditName.getText().toString();
			
			//check if the name is illegal.
			if( !Utils.checkAlbumName(name) )
			{
				mEditName.setText("");
				mEditName.requestFocus();
				return;
			}
			
			AlbumContext.getAlbumManager().createAlbum(name);
			CreateAlbumActivity.this.finish();
		}
	};
	
	private View.OnClickListener mBtnCancelListener = new View.OnClickListener() {		
		@Override
		public void onClick(View v) {
			CreateAlbumActivity.this.finish();
		}
	};
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.view_create_album);   
        
        mEditName = (EditText)findViewById(R.id.create_album_name);
        mBtnOK = (Button)findViewById(R.id.create_album_ok);
        mBtnOK.setOnClickListener(mBtnOKListener);
        
        mBtnCancel = (Button)findViewById(R.id.create_album_cancel);
        mBtnCancel.setOnClickListener(mBtnCancelListener);
    }
}
